package com.badboy.mapper;

import com.badboy.entity.Forums;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author 26607
* @description 针对表【forums(管理论坛的各个版块信息)】的数据库操作Mapper
* @createDate 2025-05-10 21:16:11
* @Entity com.badboy.entity.Forums
*/
public interface ForumsMapper {
    @Select("SELECT * FROM forums")
    @Results({
            @Result(property = "forumId", column = "forum_id", id = true),
            @Result(property = "name", column = "name"),
            @Result(property = "description", column = "description"),
            @Result(property = "adminId", column = "admin_id"),
            @Result(property = "createdAt", column = "created_at")
    })
    List<Forums> getAllForums();

    @Select("SELECT * FROM forums WHERE forum_id = #{forumId}")
    @Results({
            @Result(property = "forumId", column = "forum_id", id = true),
            @Result(property = "name", column = "name"),
            @Result(property = "description", column = "description"),
            @Result(property = "adminId", column = "admin_id"),
            @Result(property = "createdAt", column = "created_at")
    })
    Forums getForumById(Integer forumId);

    @Insert("INSERT INTO forums (name, description, admin_id, created_at) " +
            "VALUES (#{name}, #{description}, #{adminId}, #{createdAt})")
    @Options(useGeneratedKeys = true, keyProperty = "forumId")
    int insertForum(Forums forum);

    @Update("UPDATE forums SET name=#{name}, description=#{description}, " +
            "admin_id=#{adminId} WHERE forum_id=#{forumId}")
    int updateForum(Forums forum);

    @Delete("DELETE FROM forums WHERE forum_id=#{forumId}")
    int deleteForum(Integer forumId);

    @Select("SELECT * FROM forums WHERE admin_id = #{adminId}")
    @Results({
            @Result(property = "forumId", column = "forum_id", id = true),
            @Result(property = "name", column = "name"),
            @Result(property = "description", column = "description"),
            @Result(property = "adminId", column = "admin_id"),
            @Result(property = "createdAt", column = "created_at")
    })
    List<Forums> getForumsByAdminId(Integer adminId);

    int deleteByPrimaryKey(Long id);

    int insert(Forums record);

    int insertSelective(Forums record);

    Forums selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Forums record);

    int updateByPrimaryKey(Forums record);

}
